import { actions } from "../config/constants";
import { program } from "commander";
import createProjectAction from "./create";

const commands = () => {
  // Reflect.ownKeys获取actions属性数组
  Reflect.ownKeys(actions).forEach((action: any) => {
    program
      .command(action) // 配置命令名称
      .alias(actions[action].alias) // 配置命令别名
      .description(actions[action].description) // 配置命令描述
      .action(() => {
        if (action === "*") {
          // 目前只处理create命令  其他命令均输出command not found
          console.log(actions[action].description);
        } else {
          // 从命令行获取第三个参数，并将其作为字符串存储在变量projectName中
          const projectName = process.argv.slice(3).toString();
          // 构建项目
          createProjectAction(projectName);
        }
      });
  });
};
export default commands;
